package cn.tedu.flower.manage.content.dao.persist.repository.impl;

import cn.tedu.flower.manage.common.pojo.vo.PageData;
import cn.tedu.flower.manage.common.util.PageInfoToPageDataConverter;
import cn.tedu.flower.manage.content.dao.persist.mapper.MemberMapper;
import cn.tedu.flower.manage.content.dao.persist.repository.IMemberRepository;
import cn.tedu.flower.manage.content.pojo.entity.Member;
import cn.tedu.flower.manage.content.pojo.vo.GoodsListItemVO;
import cn.tedu.flower.manage.content.pojo.vo.MemberListItemVO;
import cn.tedu.flower.manage.content.pojo.vo.MemberStandardVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

@Slf4j
@Repository
public class MemberRepositoryImpl implements IMemberRepository {
    @Autowired
    MemberMapper memberMapper;

    @Override
    public int insert(Member member) {
        log.debug("开始执行【插入会员】的数据访问，参数：{}", member);
        return memberMapper.insert(member);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除会员】的数据访问，参数：{}", id);
        return memberMapper.deleteById(id);
    }

    @Override
    public int deleteByIds(Collection<Long> idList) {
        log.debug("开始执行【批量删除会员】的数据访问，参数：{}", idList);
        return memberMapper.deleteBatchIds(idList);
    }

    @Override
    public int update(Member member) {
        log.debug("开始执行【更新会员】的数据访问，参数：{}", member);
        return memberMapper.updateById(member);
    }

    @Override
    public int count() {
        log.debug("开始执行【统计会员的数量】的数据访问，参数：无");
        return memberMapper.selectCount(null);
    }

    @Override
    public MemberStandardVO selectById(Long id) {
        log.debug("开始执行【根据ID查询会员信息】的数据访问，参数：{}", id);
        return memberMapper.selectById(id);
    }

    @Override
    public MemberStandardVO selectByUsername(String username) {
        log.debug("开始执行【根据用户名查询会员信息】的数据访问，参数：{}", username);
        return memberMapper.selectByUsername(username);
    }

    @Override
    public PageData<MemberListItemVO> selectAll(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询会员信息】的数据访问，参数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum,pageSize);
        List<MemberListItemVO> list = memberMapper.selectAll();
        PageInfo<MemberListItemVO>pageInfo=new PageInfo<>(list);
        PageData<MemberListItemVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }


    @Override
    public MemberStandardVO selectByNickname(String nickname) {
        log.debug("开始执行【根据昵称查询会员信息】的数据访问，参数：{}", nickname);
        return memberMapper.selectByNickname(nickname);
    }


}
